package com.zx.JDK特性.jdk1_8.date;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;

/**
 * @author zhangxue
 * @title 代表的是时间戳
 */
public class InstantDemo {

    public static void main(String[] args) {
        // 当前时间的时间戳
        Instant now = Instant.now();
        System.out.println(now);

        long currentTimeMillis = System.currentTimeMillis();
        // 使用毫秒值转为时间戳
        Instant ofEpochMilli = Instant.ofEpochMilli(currentTimeMillis);
        //时间戳转LocalDateTime
        LocalDateTime.ofInstant(ofEpochMilli, ZoneId.systemDefault());

        //LocalDateTime转时间戳
        LocalDateTime localDateTime = LocalDateTime.now();
        Instant i1 = localDateTime.toInstant(ZoneOffset.ofHours(8));
        Instant i2 = localDateTime.toInstant(ZoneOffset.of("+08:00"));
        Instant i3 = localDateTime.atZone(ZoneId.systemDefault()).toInstant();
        System.out.println(i1);
        System.out.println(i2);
        System.out.println(i3);
    }
}
